<?php

namespace backend\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "{{%jjr_user_withdraw}}".
 *
 * @property int $id
 * @property int $jjr_user_commission_id
 * @property int $jjr_user_id 经纪人ID
 * @property string $amount 转账金额
 * @property int $card_no 银行卡号
 * @property string $bank_name 银行名称
 * @property string $card_real_name 转账人
 * @property string $bank_branch_name 转账人银行支行
 * @property string $create_time 创建时间
 * @property string $update_time 更新时间
 * @property int $status
 * @property string $fail_reason 失败原因
 * @property int $transfer_status 1转账中，2已转账，3转账失败
 */
class JjrUserWithdraw extends \common\core\BaseActiveRecord
{
    const TRANSFER_NOT_START="1";
    const TRANSFER_STARTED="2";
    const TRANSFER_END="3";
    const TRANSFER_FAIL="4";
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%jjr_user_withdraw}}';
    }
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    # 创建之前
                    \yii\db\ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
                    # 修改之前
                    \yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => ['update_time']
                ],
                #设置默认值
                'value' =>date('Y-m-d H:i:s')
            ]
        ];
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [[ 'transfer_status'], 'required'],
            [[ 'jjr_user_commission_id', 'jjr_user_id' , 'status', 'transfer_status'], 'integer'],
            [['amount'], 'number'],
            [['create_time', 'update_time'], 'safe'],
            [['bank_name', 'card_real_name', 'bank_branch_name','card_no', 'fail_reason'], 'string', 'max' => 255],
            [['id'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'jjr_user_commission_id' => '佣金ID',
            'jjr_user_id' => '经纪人ID',
            'amount' => '转账金额',
            'card_no' => '银行卡号',
            'bank_name' => '银行名称',
            'card_real_name' => '转账人',
            'bank_branch_name' => '转账人银行支行',
            'create_time' => '创建时间',
            'update_time' => '更新时间',
            'status' => 'Status',
            'fail_reason' => '失败原因',
            'transfer_status' => '转账状态',//1未转账，2转账中，3已转账，4转账失败
        ];
    }
}
